package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcEvaluationEntity;
import com.dhcc.cdc.busi.service.ICdcEvaluationService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 评估
 * 
 * @ClassName: CdcEvaluationController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:08
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcevaluation")
public class CdcEvaluationController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcevaluation/";

	@Autowired
	private ICdcEvaluationService cdcEvaluationService;
	

    /**
     * 跳转到评估列表首页
     */
    @RequestMapping("")
    @Permission("cdcevaluation:list")
    public String index() {
        return PREFIX + "cdcevaluation.html";
    }
	
    /**
     * 跳转到新增评估
     */
    @RequestMapping("/to_add")
    @Permission("cdcevaluation:add")
    public String toAdd() {
        return PREFIX + "cdcevaluation_add.html";
    }
	
	/**
     * 跳转到修改评估
     */
    @RequestMapping("/to_update/{cdcEvaluationId}")
    @Permission("cdcevaluation:update")
    public String toUpdate(@PathVariable Long cdcEvaluationId, Model model) {
        CdcEvaluationEntity cdcEvaluation = this.cdcEvaluationService.selectById(cdcEvaluationId);
        model.addAttribute("cdcEvaluation",cdcEvaluation);
        return PREFIX + "cdcevaluation_edit.html";
    }

    /**
     * 获取评估列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcevaluation:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcEvaluationEntity> page = new PageFactory<CdcEvaluationEntity>().defaultPage();
        List<CdcEvaluationEntity> result = this.cdcEvaluationService.page(page,params);
        page.setRecords((List<CdcEvaluationEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增评估
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcevaluation:add")
    @BussinessLog(value = "新增评估")
    public Object add(CdcEvaluationEntity cdcEvaluation) {
        if (CommonUtil.isOneEmpty(cdcEvaluation)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcEvaluation.insert();
        return R.ok();
    }

    /**
     * 删除评估
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcevaluation:delete")
    @BussinessLog(value = "删除评估")
    public Object delete(@RequestParam Long cdcEvaluationId) {
	
        this.cdcEvaluationService.deleteById(cdcEvaluationId);

        return R.ok();
    }

    /**
     * 修改评估
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcevaluation:update")
    @BussinessLog(value = "修改评估")
    public Object update(CdcEvaluationEntity cdcEvaluation) {
        if (CommonUtil.isOneEmpty(cdcEvaluation)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcEvaluationEntity old = this.cdcEvaluationService.selectById(cdcEvaluation.getId());

        old.setEpisodeId(cdcEvaluation.getEpisodeId());
        old.setCode(cdcEvaluation.getCode());
        old.setDescription(cdcEvaluation.getDescription());
        old.setResult(cdcEvaluation.getResult());
        old.setEvalDate(cdcEvaluation.getEvalDate());
        old.setDataId(cdcEvaluation.getDataId());
        old.setIsActive(cdcEvaluation.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
